﻿// owner 蒋家伟

#pragma once
#include "DataSchema_home.h"

namespace jsdk
{
    // 稳定字节数4+2+2+8 = 16;
    struct Uid
    {
        uint32_t data1{};
        uint16_t data2{};
        uint16_t data3{};
        uint8_t data4[8]{};
    };

    // 类别描述 ：UUid再封装
    class DATASCHEMA_EXPORT UniqueId
    {
    public:
        UniqueId();
        UniqueId(const UniqueId& uid);
        UniqueId &operator=(const UniqueId& uid);
        bool operator<(const UniqueId& uid) const;
        bool operator>(const UniqueId& uid) const;
        bool operator==(const UniqueId& uid) const;
        bool operator!=(const UniqueId& uid) const;

    public:
        static UniqueId s_InvalidUId;

        /// \ brief 创建一个有效的uuid
        /// \ in description 当前uid的描述
        static UniqueId create();

        /// \ brief 从字符转换到UniqueId 
        /// \ in uidStr {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}
        /// \ note :  如果格式不满足则返回无效值
        /// \ return UniqueId
        static UniqueId fromWString(const std::wstring& uidStr);

    public:
        /// \ brief 判断当前uid是否有效
        bool isValid() const;

        /// \ brief 转换成字符串
        /// \ return {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}
        std::wstring toString() const;

        /// \ brief 获取存储的uid
        const Uid& getUid() const;

    private:
        Uid m_uid{};
    };

    struct DATASCHEMA_EXPORT Hash_UniqueId
    {
        size_t operator()(const UniqueId& uniqueId) const;
    };
}
